<template>
  <div id="app">
    <ul>
      <li v-for="(item, ind) in arr" :key="ind">
        <span>{{ item }}</span>
        <button @click="on(ind)">删除</button>
      </li>
    </ul>
    <button @click="fn">生成</button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      arr: [5, 7, 1],
    };
  },
  methods: {

    fn(){
        // 生成1-10的随机数追加到arr数组
        this.arr.push(parseInt(Math.random()*10+1))
    },
    
    //拿到遍历的下标
    on(index){
      //对应该下标删除
        this.arr.splice(index, 1)
    }

  },
};
</script>

<style>
</style>
